//
//  LoginViewController.m
//  IFengNews
//
//  Created by lanou3g on 16/3/4.
//  Copyright © 2016年 徐强. All rights reserved.
//

#import "LoginViewController.h"
#import "RegViewController.h"
#import "FindPassWordViewController.h"
#import "ChangePasswordViewController.h"
@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *passWord;


@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //点击空白处回收键盘
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [self.view addGestureRecognizer:tap];
}
- (void)viewWillDisappear:(BOOL)animated{
    self.userName.text = nil;
    self.passWord.text = nil;
}
- (void)tapAction{
    [self.view endEditing:YES];
}
//正在登录界面
- (IBAction)logining:(UIButton *)sender {
     NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([user objectForKey:self.userName.text] == nil) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"账户未注册" preferredStyle:(UIAlertControllerStyleAlert)];
        [self presentViewController:alert animated:YES completion:^{
            sleep(1);
            [self dismissViewControllerAnimated:YES completion:nil];
        }];
    }else{
        //登陆时账号和密码与存储的一致
        if ([self.passWord.text isEqualToString:[user objectForKey:self.userName.text]]) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"登陆成功" preferredStyle:(UIAlertControllerStyleAlert)];
            self.onLine = YES;
            [self presentViewController:alert animated:YES completion:^{
                sleep(1);
                [self dismissViewControllerAnimated:YES completion:^{
                    
                    [self dismissViewControllerAnimated:YES completion:nil];
                }];
            }];
        }else{
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"账户密码错误！" preferredStyle:(UIAlertControllerStyleAlert)];
            [self presentViewController:alert animated:YES completion:^{
                sleep(1);
                [self dismissViewControllerAnimated:YES completion:nil];
            }];
        }
    }
}
//退出登录界面
- (IBAction)escLogin:(UIButton *)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}
//跳转到注册界面
- (IBAction)reg:(UIButton *)sender {
    RegViewController *regV = [[RegViewController alloc]init];
    [self presentViewController:regV animated:YES completion:nil];
    
}
//找回密码
- (IBAction)findBackPassWord:(UIButton *)sender {
    FindPassWordViewController *findPassWord = [[FindPassWordViewController alloc]init];
    [self presentViewController:findPassWord animated:YES completion:nil];
    
}
//修改密码
- (IBAction)changePassWord:(UIButton *)sender {
    ChangePasswordViewController *changeVC = [[ChangePasswordViewController alloc]init];
    [self presentViewController:changeVC animated:YES completion:nil];
    
}


@end
